<template>
	<view class="container">
		<view>
			<button @click='chooseImage()'>选择图片</button>
			<view v-if="imgs" v-for="(item,index) in imgs" :key="index">
				<image :src='item' style='width:100rpx;height:100rpx;'></image>
			</view>
			<button @tap='upLoadImage'>上传图片</button>
		</view>
		
		
		<div class="popup" v-if="showPrivacy">
			<div class="popcontent">
				<div class="poptext">您在使用【上岸数据助手】服务之前，请自仔细阅读《上岸数据助手小程序隐私保护指引》。如您同意《上岸数据助手小程序隐私保护指引》，请点击同意开始使用【上岸数据助手】。</div>
				<div class="btns">
					<div class="btn"><u-button type="primary" size="small" @tap="handleOpenPrivacyContract">查看隐私协议</u-button></div>
					<div class="btn"><u-button type="error" size="small" id="agree-btn" open-type="agreePrivacyAuthorization" @click="handleAgreePrivacyAuthorization">同意</u-button></div>
				</div>
			</div>
		</div>
	</view>
</template>

<script>
	export default {
		name: 'headcomd',
		data() {
			return {
				showPrivacy:false,
				imgs: [],
				openid: ""
			};
		},
		onShareAppMessage(options) {},
		onLoad(options) {
			if (wx.getPrivacySetting) {
				wx.getPrivacySetting({
					success: res => {
						console.log(res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
						if (res.needAuthorization) {
							// 需要弹出隐私协议
							this.showPrivacy = true
						} else {
							
						}
					},
					fail: () => {},
					complete: () => {}
				})
			}
		},
		computed: {

		},
		mounted() {

		},
		watch: {

		},
		created() {
			let that = this;

		},
		methods: {
			handleAgreePrivacyAuthorization() {
				this.showPrivacy = false
			},
			handleOpenPrivacyContract() {
				// 打开隐私协议页面
				wx.openPrivacyContract({
					success: () => {}, // 打开成功
					fail: () => {}, // 打开失败
					complete: () => {}
				})
			},
			chooseImage() {
				var that = this;
				wx.chooseImage({
					count: 1, // 默认9
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
					success: function(res) {
						// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
						var tempFilePaths = res.tempFilePaths
						console.log('1', tempFilePaths);
						that.imgs = tempFilePaths
					},
					fail:function(req){
						console.log(req)
					}
				})
			},
			upLoadImage(tempFilePaths) {
				let that = this
				wx.showLoading({
					title: '图片上传中',
				})
				wx.uploadFile({
					url: 'https://www.baixuemianshi.com/zhuanti/upload_img/xcx.php', //仅为测试地址，填写你的url即可
					filePath: that.imgs[0],
					name: 'file',
					success: function(res) {
						console.log(res)
						if (res.statusCode == 200) {
							console.log(res)
						}
					},
					error: function(res) {
						console.log("上传失败!")
					},
				})
				wx.hideLoading();
			}

		}
	};
</script>

<style>
	@import url("./index.css");
</style>